using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using TCEntity;

namespace TCClientService
{
  public static class ShareService
  {
    /// <summary>
    /// 分享图片。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="imageId">图像Id。</param>
    /// <param name="communityId">社区Id。</param>
    /// <param name="success">成功时执行的方法。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task ShareAsync(this HttpClient client, User user, int imageId, int communityId, Action success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Post, "./Share/share");
      await TCHttpService.SendAsync<object>(client, request, (user, imageId, communityId), _ => success(), failure, InternetFailure);
    }
    public static async Task ShareAsync(this HttpClient client,Image image, Action success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Put, "./Share/update");
      await TCHttpService.SendAsync<object>(client, request, image, _ => success(), failure, InternetFailure);
    }

    /// <summary>
    /// 查看社区图片。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="communityId">社区Id。</param>
    /// <param name="success">成功时执行的方法，传入结果图像和分享Id列表。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>

    public static async Task ViewAsync(this HttpClient client, User user, int communityId, Action<List<(Image,int)>> success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Get, "./Share/view");
      await TCHttpService.SendAsync(client, request, (user, communityId), success, failure, InternetFailure);
    }
    /// <summary>
    /// 取消分享。
    /// </summary>
    /// <param name="client">HTTP客户端。</param>
    /// <param name="user">给定用户。</param>
    /// <param name="shareId">分享Id。</param>
    /// <param name="success">成功时执行的方法。</param>
    /// <param name="failure">失败时执行的方法，传入失败原因字符串。</param>
    /// <param name="InternetFailure">网络错误时执行的方法。</param>
    /// <returns></returns>
    public static async Task CancelAsync(this HttpClient client, User user, int shareId, Action success, Action<string> failure, Action InternetFailure)
    {
      var request = new HttpRequestMessage(HttpMethod.Delete, "./Share/cancel");
      await TCHttpService.SendAsync<object>(client, request, (user, shareId), _ => success(), failure, InternetFailure);
    }

  }
}
